#include <stdio.h>

int read_numbers(char* filename, int* dest, int maxinput) {
    FILE* fp = fopen(filename, "r");
    if (fp == NULL) {
        fprintf(stderr, "error: cannot open %s\n", filename);
        return 0;
    }
    
    int i;
    for (i = 0; !feof(fp); i++) {
        if (i == maxinput) {
            fprintf(stderr, "error: no space available !\n");
            break;
        }
        fscanf(fp, "%d ", &dest[i]);
    }
    printf("Have read %d numbers\n", i);
    fclose(fp);

    return i;
}

void print_numbers(int dest[], int pos)
{
    for (int i = 0; i < pos; i++) {
        if (i != 0 && i % 20 == 0)
            printf("\n");
        if (i == 1000) {
            printf("\nThere are %d numbers .....\n", pos - 1000);
            break;
        }
        printf("%7d ", dest[i]);
    }
    printf("\n");
}
